home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 7
/
FM Towns Free Software Collection 7.iso
/
ms_dos
/
dmove86
/
fat_dpb.c
< prev
next >
Wrap
Text File
|
1993-11-30
|
2KB
|
97 lines
/*
fat_dpb.c -- FATとDPBの操作関数
*/
#include<stdio.h>
#include<dos.h>
#include<ctype.h>
#include<process.h>
#include<malloc.h>
#include"dmove86.h"
extern struct DPB Dpb;
extern int Drive;
extern unsigned int Fatsize;
int getdpb(void)
{ union REGS regs;
struct SREGS seg;
regs.h.ah = 0x32;
regs.h.dl = Drive + 1;
int86x(0x21,®s,®s,&seg);
if (regs.h.al == 0xff)
return -1;
Dpb = *(struct DPB far *)MK_FP(seg.ds, regs.x.bx);
Fatsize = (Dpb.data_sec - Dpb.iplsectors
- Dpb.root_entry/(Dpb.seclen >> 5)) / Dpb.fatnum;
#ifdef DEBUG
printf("FAT size = %u\n",Fatsize);
#endif
return 0;
}
unsigned int *getfat(void)
{
unsigned int af;
unsigned int pos;
char *buf;
buf = (char *)malloc(Dpb.seclen * Fatsize);
if (buf == 0)
{
#ifdef DEBUG
printf("Not enough memory for malloc()\n");
#endif
return 0 ;
}
for (pos=0 ; pos<Fatsize ; pos++)
{
af = rdabssec((void far *)(buf + pos*Dpb.seclen),
Dpb.iplsectors+pos,Drive);
#ifdef DEBUG
printf("AF=%4x\n",af);
#endif
}
if (Dpb.maxclu < 0xff7)
{ /* 12ビットFAT */
unsigned *fat;
fat=(unsigned *)malloc( (Dpb.maxclu+2) * sizeof(unsigned) );
if (fat == 0)
{
#ifdef DEBUG
printf("12bit FAT:not enough memory for malloc\n");
#endif
free(buf);
return 0;
}
for (pos=0 ; pos < Dpb.maxclu/2 ; pos++)
{
fat[pos*2 ] = buf[pos*3 ]+ (buf[pos*3+1]&0x0f) * 256;
fat[pos*2+1] = buf[pos*3+1]/16 + buf[pos*3+2]*16;
if (fat[pos*2 ] > 0xff6) fat[pos*2 ] |= 0xf000;
if (fat[pos*2+1] > 0xff6) fat[pos*2+1] |= 0xf000;
}
free(buf);
return (fat);
}
else return (unsigned int *)buf;
}